package org.example.erpdemo.demos.service;

import org.example.erpdemo.demos.mapper.SaleOrderMapper;
import org.example.erpdemo.demos.model.SaleOrder;
import org.example.erpdemo.demos.model.SaleOrderLine;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SaleOrderService {

    @Autowired
    private SaleOrderMapper saleOrderMapper;

    public void createSaleOrder(SaleOrder order, List<SaleOrderLine> lines) {
        order.setCreatedOn(new Date()); // 设置创建时间
        saleOrderMapper.insertSaleOrder(order);
        for (SaleOrderLine line : lines) {
            line.setOrderId(order.getId()); // 设置订单ID
        }
        saleOrderMapper.insertSaleOrderLines(lines);
    }
}
